package com.acoreful.bootsample.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("test")
@RestController
public class TestController {
	private Logger logger=LoggerFactory.getLogger(TestController.class);
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	@GetMapping
	public String test() {
		stringRedisTemplate.opsForHash().put("user:","1","sdfsdfsd");
		String str=(String) stringRedisTemplate.opsForHash().get("user:","1");
		System.out.println(str);
		return "success";
	}
	@GetMapping("1")
	public String test1() {
		stringRedisTemplate.opsForHash().put("user:","1","小明");
		String str=(String) stringRedisTemplate.opsForHash().get("user:","1");
		logger.info(str);
		RedisAtomicLong counter = new RedisAtomicLong("rest_token", stringRedisTemplate.getConnectionFactory());
		//counter.set(1);
		//counter.expire(1, TimeUnit.DAYS);
		return counter.getAndIncrement()+"";
	}
	
}
